package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 执行聚合函数
 */
public class JDBCDemo7 {
    public static void main(String[] args) {
        //需求:查看1年级1班一共多少人
        /**
         * from student s
         * join class c on s.class_id=c.id
         * where c.name='1年级1班'
         */
        try(
                Connection connection =DBUtil.getConnection();
                ){
            Statement statement =connection.createStatement();
            String sql="select count(*) count " +
                    "from student s " +
                    "join class c on s.class_id=c.id " +
                    "where c.name='1年级1班' ";
            ResultSet rs=statement.executeQuery(sql);
            if (rs.next()){
                int count =rs.getInt("count");
                System.out.println("共"+count+"人");
            }
        }catch (SQLException e){
            e.printStackTrace();
        }






    }
}
